import { getSignalList } from "@/api/production/device";
import { getDeviceUse, getDeviceParams,lineParamAndGlasses } from "@/api/assembly/device"
import { listPlcSignal } from "@/api/assembly/signal"
import { deviceRecumentDB, edgeDB, cleanDB } from "@/config/db"
import { getAllCameraScanGlass } from "@/api/assembly/camera";
const state = {
    deviceStatus: [],
    deviceUseList: [],
    // 3台卧理机plc状态
    deviceList: [],
    deviceParams: [],
    allCameraList: []
};

const mutations = {
};
const actions = {
    async listOperationStatus({ state, commit }) {
        const res = await getSignalList()
        if (res.code == 200) {
            state.deviceStatus = res.rows[0]
        }
    },
    // 获取设备启动的状态
    async deviceStatus({ state, commit }) {
        const res = await getDeviceUse();
        state.deviceUseList = res.data
    },
    // plc
    async getDeviceSignal({ state }, params) {
        const res = await listPlcSignal(params);
        state.deviceList = res.data
    },
    // 获取设备状态可修改值
    async getDeviceMap({ state }, params) {
        const res = await getDeviceParams(params);
        state.deviceParams = res.data
    },
    async AllCameraScanGlass({ state }, params) {
        await getAllCameraScanGlass().then((res) => {
            state.allCameraList = res.data;
        });
    },
    // 置空deviceList
    clearDeviceList({ state }) {
        state.deviceList = []
    },
    // 获取在中空线玻璃数据
    async getKongLineGalss({ state }, params) {
        const res = await lineParamAndGlasses(params);
        state.deviceParams = res.data[0]
    },
};

const getters = {
    recumentStatusList: (state) => {
        if (state.deviceList.length == 0) return []

        let recumentId = [2, 3]
        let list = state.deviceList.filter((item => item.hasOwnProperty("assemblyDevice") && item.assemblyDevice != null && recumentId.includes(item.assemblyDevice.id))).map((item, index) => item.plcSignals.filter(a => {
            return deviceRecumentDB[index].block == a.block
        }))
        return list
    },
    edgeStatusList: (state) => {
        if (state.deviceList.length == 0) return []
        let recumentId = [6, 7, 8, 9, 10]
        let list = state.deviceList.filter((item => item.hasOwnProperty("assemblyDevice") && item.assemblyDevice != null && recumentId.includes(item.assemblyDevice.id))).map((item, index) => item.plcSignals.filter(a => {
            return edgeDB[index].block == a.block
        }))
        return list
    },
    cleanStatusList: (state) => {
        if (state.deviceList.length == 0) return []
        let recumentId = [11, 12, 13, 14, 15]
        let list = state.deviceList.filter((item => item.hasOwnProperty("assemblyDevice") && item.assemblyDevice != null && recumentId.includes(item.assemblyDevice.id))).map((item, index) => item.plcSignals.filter(a => {
            return cleanDB[index].block == a.block
        }))
        return list
    }
};
export default {
    state,
    mutations,
    actions,
    getters
}